package com.shangyueshang.controller.sale;

import com.shangyueshang.model.Goods;
import com.shangyueshang.request.GoodsDTO;
import com.shangyueshang.request.PageReq;
import com.shangyueshang.response.HttpResult;
import com.shangyueshang.response.PageResult;
import com.shangyueshang.service.GoodsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author: JokeyZheng
 * @email: zhengjingfeng@ruqimobility.com
 * @created: 2022/1/14 15:33
 * @version: v1.0.0
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
	
	@Resource
	private GoodsService goodsService;
	
	/**
	 * 分页查询
	 *
	 * @param pageReq
	 * @return
	 */
	@PostMapping("/findPage")
	@PreAuthorize("hasAuthority('sale:goods:view')")
	public HttpResult<PageResult<Goods>> findPage(@RequestBody PageReq pageReq) {
		return HttpResult.ok(goodsService.findPage(pageReq));
	}
	
	/**
	 * 保存产品信息
	 *
	 * @param goodsDTO
	 * @return
	 */
	@PostMapping("/save")
	@PreAuthorize("hasAnyAuthority('sale:goods:add','sale:goods:edit')")
	public HttpResult<Void> save(@Valid @RequestBody GoodsDTO goodsDTO) {
		return goodsService.save(goodsDTO);
	}
}
